package com.example.yuejian.yuejian.adapter;


import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.activity.MatchDetailActivity;
import com.example.yuejian.yuejian.bean.Match;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/9/18.
 */

public class HomeMatchAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
    private Context mContext;;
    private List mDataList;
    public LayoutInflater mLayoutInflater;

    public HomeMatchAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.inflate(R.layout.cardview_home_match, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      final Match entity = (Match) mDataList.get(position);
        if (null == entity)
            return;
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.match_title.setText(entity.getName());
        if (!"".equals(entity.getPhoto()))
        {
            Picasso.with(mContext).load(entity.getPhoto()).into(viewHolder.match_image);
        }
        else {
            viewHolder.match_image.setImageResource(R.drawable.camera);
        }

        viewHolder.match_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, MatchDetailActivity.class);
                intent.putExtra("match_id",entity.getId()+"");
                mContext.startActivity(intent);
               /* final SharedPreferences sharedPreferences=mContext.getSharedPreferences("Mid", MODE_PRIVATE);
                SharedPreferences.Editor editor=sharedPreferences.edit();//获取编辑器
                editor.putString("m_id", entity.getId()+"");
                editor.commit();*/

            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        //TextView master_name;
       ImageView match_image;
       TextView match_title;
        //TextView master_follow_num;
       // ImageView imageView_follow;
        LinearLayout match_detail;

        public ViewHolder(View itemView) {
            super(itemView);
            //imageView_follow=itemView.findViewById(R.id.img_home_teacher_heart);

            match_image = (ImageView) itemView.findViewById(R.id.home_match_image);
            match_title= (TextView) itemView.findViewById(R.id.home_match_title);
            match_detail=(LinearLayout)itemView.findViewById(R.id.cardview_home_match_detail);

        }
    }

}
